

public class ACKResponse extends IResponse {

	protected ACKResponse(byte[] data, ICommand command) {
		super(data, command);
		if (!command.getClass().equals(ProbeCommand.class) && !command.getClass().equals(FetchCommand.class)) {
			throw new IllegalArgumentException("Wrong command passing in.");
		}
	}

	@Override
	public void run() {
		int type = this.comm.getType();

		String commandType = Util.getCommandTypeInEnglish(type);
		
		if (type == 0x05) {
			// Unregister			
			FetchCommand fcomm = (FetchCommand) this.comm;
			String serviceName = (fcomm.getServiceName() == null) ? "" : fcomm.getServiceName();
			
			System.out.println("[SERVER] " + commandType + " acknowledged. Service name: " + serviceName 
					+ " (sequence number: " + comm.getSeqNum() + ")");
		} else if (type == 0x06) {
			// Probe
			System.out.println("[SERVER] " + commandType + " succeeded. (sequence number: " + comm.getSeqNum() + ")");
		} else {
			// Only expecting acks to Unregister and Probe commands for now
			System.out.println("[SERVER] Received unexpected ACK (sequence number: " + comm.getSeqNum() + ")");
		}
	}

}
